Plotting API


UXarray provides a fully-fledged plotting API for visualizing unstructured grids.

This notebook will introduce how to interact with plotting methods directly though UXarray data structures.

Note

This notebook acts as an introduction into using the UXarray plotting API. The following notebooks in this section provide a detailed overview of visualuzation techniques.

import uxarray as ux
/home/runner/miniconda3/envs/cookbook-dev/lib/python3.10/site-packages/dask/dataframe/_pyarrow_compat.py:17: FutureWarning: Minimal version of pyarrow will soon be increased to 14.0.1. You are using 12.0.1. Please consider upgrading.
  warnings.warn(
file_dir = "../../meshfiles/"
grid_filename = file_dir + "oQU480.grid.nc"
data_filename = file_dir + "oQU480.data.nc"
grid = ux.open_grid(grid_filename)
uxds = ux.open_dataset(grid_filename, data_filename)

Grid Plotting

For visualizing the topology (i.e. geometry) of an unstructured grid, plotting is done through a Grid Instance

grid.plot(title="Default Grid Plot")

You can call specific plotting routines through the plot accessor

grid.plot.nodes(title="Grid Node Plot")

If you have a UxDataset or UxDataArray, you can access the Grid through the uxgrid attribute.

uxds.uxgrid.plot(title="Default Grid Plot through uxgrid attribute")

UxDataset & UxDataArray Plotting

For visualizing data variables, plotting is done a UxDataArray instance.

uxds["bottomDepth"].plot(title="Default UxDataArray Plot")

As was shown with a Grid, you can call specific plotting routines through the plot accessor

uxds["bottomDepth"].plot.points(title="UxDataArray Point Plot")

Plotting a UxDataset currently not supported

uxds.plot()
/home/runner/miniconda3/envs/cookbook-dev/lib/python3.10/site-packages/uxarray/plot/accessor.py:457: UserWarning: Plotting for UxDataset instances not yet supported. Did you mean to plot a data variable, i.e. uxds['data_variable'].plot()
  warnings.warn(

Customization

UXarray’s plotting API is built around the Holoviews Python package. For details about customizing plots, expected parameters, and other features, you can refer to their documentation. Below are brief examples on how to customize plots.

Figure Size

grid.plot(width=500, height=250)

Creating Subplots

(
    grid.plot(width=500, height=250, color="Black")
    + grid.plot(width=500, height=250, color="Blue")
    + grid.plot(width=500, height=250, color="Red")
    + grid.plot(width=500, height=250, color="Green")
).cols(2)
(
    grid.plot(width=500, height=250, color="Black")
    + grid.plot(width=500, height=250, color="Blue")
    + grid.plot(width=500, height=250, color="Red")
    + grid.plot(width=500, height=250, color="Green")
).cols(1)

add a few more examples